import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs'

import App from './App.vue'
import router from './router'
import { i18n } from './i18n'
import { useAppStore } from './stores/app'
import './style.css'

// 创建应用实例
const app = createApp(App)

// 注册 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 使用Pinia
const pinia = createPinia()
app.use(pinia)

// 初始化应用存储
const appStore = useAppStore(pinia)

// 设置Element Plus的语言
const locale = i18n.global.locale.value
const elementLocale = locale === 'zh-CN' ? zhCn : en
app.use(ElementPlus, { locale: elementLocale })

// 使用路由和i18n
app.use(router)
app.use(i18n)

// 初始化主题
appStore.initTheme()

// 挂载应用
app.mount('#app')
